home *** CD-ROM | disk | FTP | other *** search
/ Revista do CD-ROM 97 / CD-ROM 97 / CD-ROM 97.iso / jogos / spherical / Code / Game / main.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  2002-08-04  |  6.4 KB  |  250 lines

  1.  
  2. // Copyright (C) 2002 by Luigi Pino.  All Rights Reserved.
  3.  
  4. /***************************************************************************/
  5.  
  6. #include "../library/neurosis.h"
  7. #include "draw.h"
  8. #include "file_io.h"
  9. #include "hiscore.h"
  10. #include "initialize.h"
  11. #include "main.h"
  12. #include "menu_misc.h"
  13. #include "paddle.h"
  14. #include "sphere.h"
  15. #include "update.h"
  16.  
  17. /***************************************************************************/
  18.  
  19. Camera_Class                    camera;
  20. High_Score_Struct            high_score_sphere;
  21. High_Score_Struct            high_score_time;
  22. Light_Values_Struct        light_values;
  23. Main_Menu_Class                menu;
  24. Mouse_Class                        mouse;
  25. Object3_Class                    ground_cover;
  26. Object3_Class                    paddle[4];
  27. Object3_Class                    sphere[4];
  28. Object4_Class                    ground;
  29. Object4_Class                    wall_net;
  30. Object4_Class                    wall_side;
  31. Paddle_Struct                    paddle_object[4];
  32. Shadow_Box_Struct            light_source;
  33. Sphere_Control_Struct    sphere_object[4];
  34. Sub_Menu_Class                menu_main;
  35. Sub_Menu_Class                menu_options;
  36. Sub_Menu_Class                menu_control;
  37. Sub_Menu_Class                menu_high_scores;
  38. Sub_Menu_Class                game_paused;
  39. Sub_Menu_Class                game_scores;
  40. Timing_Class                    timing;
  41. Values_Struct                    values;
  42. Window_Class                    window(Texture_Total);
  43.  
  44. bool                                    connected[8];                                            // Keyboard 1,2 - Joystick 1,2,3,4, Computer, No User
  45. char                                    high_score_name[16];
  46. float3                                wall_pts[50];
  47. int                                        goal_by_team = -1;
  48.  
  49. /***************************************************************************/
  50.  
  51. int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
  52.  
  53. {
  54.     if (Initialize_Objects() == false)
  55.         {
  56.             MessageBox(NULL, "Error In Memory Management.", "ERROR", MB_OK | MB_ICONEXCLAMATION);
  57.             window.KillGLWindow();
  58.             exit(1);
  59.         }
  60.  
  61.     Initialize_System();
  62.     Initialize_Menu();
  63.     Load_Config_File();
  64.  
  65. //    if (!window.CreateGLWindow("Spherical Vengeance", 640, 480, 16, false))
  66.     if (!window.CreateGLWindow("Spherical Vengeance", window.screen_width, window.screen_height, 16, true))
  67.         exit(1);
  68.  
  69.     Initialize_Textures(false);
  70.     timing.Update();
  71.  
  72.     while (window.quit_game == false)
  73.         {
  74.             timing.Update();
  75.             window.Process_Messages();
  76.  
  77.             if (window.active)
  78.                 {
  79.                     glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
  80.                     glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
  81.  
  82.                     if (values.game_position == Game_Intro)
  83.                         {
  84.                             window.Font_Begin();
  85.                             Intro();
  86.                             window.Font_End();
  87.                         }
  88.                     else if (values.game_position == Game_Menu)
  89.                         {
  90.                             window.Font_Begin();
  91.                             Menu();
  92.                             window.Font_End();
  93.                         }
  94.                     else if (values.game_position == Game_Play)
  95.                         Game();
  96.                     else if (values.game_position == Game_Ending)
  97.                         {
  98.                             window.Font_Begin();
  99.                             Ending();
  100.                             window.Font_End();
  101.                         }
  102.  
  103.                     SwapBuffers(window.hDC);
  104.                 }
  105.         }
  106.  
  107.     // Shutdown
  108.     window.KillGLWindow();
  109.     return (window.msg.wParam);
  110. }
  111.  
  112. /***************************************************************************/
  113.  
  114. void Game()
  115.  
  116. {
  117.     int x1;
  118.  
  119.     Update_Mouse();
  120.     camera.Update(&timing);
  121.  
  122.     if (window.keys[VK_F1])
  123.         {
  124.             camera.axis_destination.x = 359.0f;
  125.             camera.axis_destination.z = 0.0f;
  126.             camera.zoom_destination = -500.0f;
  127.         }
  128.     else if (window.keys[VK_F2])
  129.         {
  130.             camera.axis_destination.x = 320.0f;
  131.             camera.axis_destination.z = 0.0f;
  132.             camera.zoom_destination = -500.0f;
  133.         }
  134.  
  135.     if (paddle_object[Up].input.user == Computer)
  136.         Paddle_AI(Up);
  137.     else if (paddle_object[Up].input.user != No_User)
  138.         Paddle_User_Input(Up);
  139.  
  140.     if (paddle_object[Down].input.user == Computer)
  141.         Paddle_AI(Down);
  142.     else if (paddle_object[Down].input.user != No_User)
  143.         Paddle_User_Input(Down);
  144.  
  145.     if (paddle_object[Left].input.user == Computer)
  146.         Paddle_AI(Left);
  147.     else if (paddle_object[Left].input.user != No_User)
  148.         Paddle_User_Input(Left);
  149.  
  150.     if (paddle_object[Right].input.user == Computer)
  151.         Paddle_AI(Right);
  152.     else if (paddle_object[Right].input.user != No_User)
  153.         Paddle_User_Input(Right);
  154.  
  155.     Update_Nets();
  156.  
  157.     for (x1=0;x1<values.sphere_number;x1=x1+1)
  158.         {
  159.             Next_Position_Sphere(x1);
  160.             Goal_Scored(x1);
  161.         }
  162.  
  163.     Draw_Items();
  164.  
  165.     // Draw time left
  166.     window.Font_Begin();
  167.     if (values.game_type != Countdown)
  168.         {
  169.             if (values.seconds_left > 0)
  170.                 {
  171.                     window.Font_Time(false, true, true, false, values.seconds_left, -310.0f, 220.0f, 30.0f, R_5, G_5, B_5);
  172.                     values.seconds_left = values.seconds_left - timing.Get_Scale();
  173.                 }
  174.         }
  175.  
  176.     if ((values.game_type == Timed) && (values.seconds_left <= 0))
  177.         {
  178.             int        count = 0;
  179.             float low_score = 10000.0f;
  180.  
  181.             // Get lowest score
  182.             for (x1=Up;x1<=Right;x1=x1+1)
  183.                 {
  184.                     if ((paddle_object[x1].game_over == false) && (paddle_object[x1].score < low_score))
  185.                         low_score = paddle_object[x1].score;
  186.                 }
  187.  
  188.             for (x1=Up;x1<=Right;x1=x1+1)
  189.                 {
  190.                     if ((paddle_object[x1].game_over == false) && (paddle_object[x1].score > low_score))
  191.                         paddle_object[x1].game_over = true;
  192.                 }
  193.  
  194.             for (x1=Up;x1<=Right;x1=x1+1)
  195.                 {
  196.                     if (paddle_object[x1].game_over == false)
  197.                         count = count + 1;
  198.                 }
  199.  
  200.             if (count > 1)
  201.                 window.Font_Char("DONT LET THE NEXT ONE IN ...", -280.0f, 220.0f, 20.0f, R_5, G_5, B_5);
  202.             else
  203.                 values.game_end_fade = true;
  204.         }
  205.     else if (values.game_type == Countdown)
  206.         {
  207.             int count = 0;
  208.  
  209.             for (x1=Up;x1<=Right;x1=x1+1)
  210.                 {
  211.                     if ((paddle_object[x1].game_over == false) && (paddle_object[x1].score < 0.0f))
  212.                         {
  213.                             paddle_object[x1].score = 0.0f;
  214.                             paddle_object[x1].game_over = true;
  215.                         }
  216.                 }
  217.  
  218.             for (x1=Up;x1<=Right;x1=x1+1)
  219.                 {
  220.                     if (paddle_object[x1].game_over == false)
  221.                         count = count + 1;
  222.                 }
  223.  
  224.             if (count <= 1)
  225.                 values.game_end_fade = true;
  226.         }
  227.     else if (values.game_type == High_Score)
  228.         {
  229.             if (values.seconds_left > 0)
  230.                 {
  231.                     window.Font_Char("SECONDS SINCE LAST GOAL:", -100.0f, 220.0f, 10.0f, R_9, G_9, B_9);
  232.                     window.Font_Float(paddle_object[Down].time_lapse, 2, 125.0f, 220.0f, 10.0f, R_9, G_9, B_9);
  233.                     window.Font_Char("MOST TIME WITH NO GOAL THIS GAME:", -100.0f, 205.0f, 10.0f, R_9, G_9, B_9);
  234.                     window.Font_Float(paddle_object[Down].time_lapse_score, 2, 125.0f, 205.0f, 10.0f, R_9, G_9, B_9);
  235.                 }
  236.  
  237.             if (values.seconds_left <= 0.0f)
  238.                 values.game_end_fade = true;
  239.         }
  240.  
  241.     window.Font_End();
  242.  
  243.     if ((window.keys[VK_ESCAPE]) && (values.game_end_fade == false))
  244.         {
  245.             menu.Set_Current(&game_paused);
  246.             values.game_position = Game_Menu;
  247.         }
  248. }
  249.  
  250. /***************************************************************************/